package com.longway.core.ext.excel.formats.model.emulate;

import com.longway.core.ext.excel.data.RowsetData;

public class Expression {

	private static Expression instance = new Expression();

    public static Expression getInstance()
    {
        return instance;
    }

    //逻辑判断//@{RWLXMC}==单位级&&@{ISKH}==1,():() 
    //逻辑判断带扩展
	public String logicResult(String expr,RowsetData rowsetData){
		String[] result = expr.split(",");
		String logicValue = result[1];
		String rLogicValue = logicValue.split(":")[0].replace("(", "").replace(")", "");
		String wLogicValue = logicValue.split(":")[1].replace("(", "").replace(")", "");
		String logic = result[0];
		String[] logics = logic.split("&&");
		String expression;
		String[] columnName = new String[logics.length ];
		int count = 0;
		for(int i = 0 ; i< logics.length ; i++){
			expression = logics[i];
			if(expression.startsWith("@")){
				expression = expression.substring(expression.indexOf("@")+1);
				if(expression.startsWith("{")){
					expression = expression.replace("{", "").replace("}", "");
					String column = expression.split("==")[0];
					String value = expression.split("==")[1];
					columnName[i] = column;
//					try {
//					String columnValue = rowsetData.getFieldString(column);
//					if(columnValue.equals(value)){
//						count++;
//					}
//					} catch (ErrorException e) {
//						e.printStackTrace();
//					}
				}
			}
			
		}
		for(int i = 0 ; i< logics.length ; i++){
//			String columnValue = rowsetData.getFieldString(column);
		}
	
		if(count == logics.length){
			return rLogicValue;
		}
		return wLogicValue;
	}
}
